<!-- breakpage 为第一页时显示的数量-->
<!-- currentpage 前面和后面显示页码的数量-->
<!-- breakSpace最前面的页数量, 和最后面的页数量-->
<!-- var maxspace = 4;-->
<!-- prevnum 上一页-->
<!-- nextnum 下一页-->

<#macro pagination action pageIndex pageSize, total, pageNum>
    <#assign maxSpace = 4 />
    <#assign breakPage = 4 />
    <#assign breakSpace = 2 />
    <#assign currentPosition = 4 />
<#--<#assign prevNum = ((pageIndex - currentPosition) lt 1) ? string(1, pageIndex - currentPosition) />-->
    <#--<#if (total % pageSize) == 0>-->
        <#--<#assign pageNum = total / pageSize />-->
    <#--<#else>-->
        <#--<#assign pageNum = total / pageSize + 1 />-->
    <#--</#if>-->

    <#if (pageIndex - currentPosition) lt 1>
        <#assign prevNum = 1 />
    <#else>
        <#assign prevNum = pageIndex - currentPosition />
    </#if>
    <#if (pageIndex + currentPosition) gt pageNum>
        <#assign nextNum = pageNum />
    <#else>
        <#assign nextNum = pageIndex + currentPosition />
    </#if>

    <div class="pagination">
        <#if pageIndex == 1>
            <span>上一页</span>
        <#else>
            <a class="prev" href="${action}${pageIndex-1}">上一页</a>
        </#if>

        <#if (prevNum - breakSpace) gt maxSpace>
            <#list 1..breakSpace as i>
                <a class="num" href="${action}${i}">${i}</a>
            </#list>
            <span class="ellipsis">...</span>
            <#list (pageNum - breakPage + 1)..(prevNum) as i>
                <a class="num" href="${action}${i}">${i}</a>
            </#list>
        <#else>
            <#list 1..(prevNum) as i>
                <a class="num" href="${action}${i}">${i}</a>
            </#list>
        </#if>

        <#list prevNum..nextNum as i>
            <#if pageIndex == i>
                <span class="current">${i}</span>
            <#else>
                <a class="num" href="${action}${i}">${i}</a>
            </#if>
        </#list>

        <#if (pageNum - breakSpace - nextNum + 1) gt maxSpace>
            <#list (nextNum + 1)..breakPage as i>
                <a class="num" href="${action}${i}">${i}</a>
            </#list>
            <span class="ellipsis">...</span>
            <#list (pageNum - breakSpace + 1)..pageNum as i>
                <a class="num" href="${action}${i}">${i}</a>
            </#list>
        <#else>
            <#list (nextNum + 1)..pageNum as i>
                <a class="num" href="${action}${i}">${i}测试</a>
            </#list>
        </#if>
        <#if pageIndex == pageNum>
            <span>下一页</span>
        <#else>
            <a class="next" href="${action}${pageIndex+1}">下一页</a>
        </#if>
    </div>
</#macro>